package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.entity.Tourism;
import com.example.mapper.TourismMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TourismService {

    @Resource
    private TourismMapper tourismMapper;

    /**
     * 新增
     */
    public void add(Tourism tourism) {
        tourism.setDate(DateUtil.today());
        tourismMapper.insert(tourism);
    }

    /**
     * 更新
     */
    public void updateById(Tourism tourism) {
        tourismMapper.updateById(tourism);
    }

    /**
     * 删除
     */
    public void deleteByid(Integer id) {
        tourismMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
/*        for (Integer id : ids) {
            tourismMapper.deleteById(id);
        }*/
        tourismMapper.deleteBatch(ids);
    }

    /**
     * 根据id查询
     */
    public Tourism selectById(Integer id) {
        return tourismMapper.selectById(id);
    }

    /**
     * 查询所有（条件查询）
     */
    public List<Tourism> selectAll(Tourism tourism) {
        return tourismMapper.selectAll(tourism);
    }

    /**
     * 分页查询（在查询所有的基础上进行分页）
     */
    public PageInfo<Tourism> selectPage(Tourism tourism,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Tourism> list = tourismMapper.selectAll(tourism);
        return PageInfo.of(list);
    }

}
